<?php
class TypodocumentsController extends AppController {

	var $name = 'Typodocuments';

    function beforeFilter () {
        parent::beforeFilter();
    }

	function index() {
		$this->Typodocument->recursive = 0;
		$this->set('typodocuments', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid typodocument', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('typodocument', $this->Typodocument->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Typodocument->create();
			if ($this->Typodocument->save($this->data)) {
				$this->Session->setFlash(__('The typodocument has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The typodocument could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid typodocument', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Typodocument->save($this->data)) {
				$this->Session->setFlash(__('The typodocument has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The typodocument could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Typodocument->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for typodocument', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Typodocument->delete($id)) {
			$this->Session->setFlash(__('Typodocument deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Typodocument was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>